import { PrismaClient } from '@prisma/client'
import { Random } from 'mockjs'
import * as bcrypt from 'bcryptjs'

const prisma = new PrismaClient()

const user = async () => {
   for (let i = 0; i < 100; i++) {
      const res = await prisma.user.create({
         data: {
            username: Random.email(),
            password: bcrypt.hashSync(Random.cword(), 10),
            nickname: Random.cname()
         }
      })

      const articel = await prisma.articel.create({
         data: {
            content: Random.cparagraph(),
            previewImg: Random.image('300x300'),
            title: Random.ctitle(),
            category: { connect: { id: Math.floor(Math.random() * 5) + 1 } },
            user: { connect: { id: res.id } }
         }
      })

      const commont = await prisma.commont.create({
         data: {
            content: Random.csentence(),
            articel: { connect: { id: articel.id } },
            user: { connect: { id: res.id } }
         }
      })

      const reply = await prisma.commont.create({
         data: {
            content: Random.csentence(),
            user: { connect: { id: res.id } },
            replyUser: { connect: { id: res.id } },
            articel: { connect: { id: articel.id } },
            reply: { connect: { id: commont.id } }
         }
      })
   }
}

export default user
